<template>
    <div>
        <div class="content">
            <div class="s-card" v-if="agent.roledec">
                <div class="s-card-text">{{ agent.roledec + "：" + agent.phone }}</div>
            </div>
            <div class="btn4" @click="reset">退出登录</div>
            <div class="card1" v-for="(item, index) in list" :key="index">

                <div class="card1-title">商户信息</div>

                <div style="display: flex;justify-content: space-around;">
                    <div class="card1-text">商户名称：{{ item.name }}</div>
                    <div class="card1-text">手机号：{{ item.phone }}</div>
                </div>
                <div style="display: flex;justify-content: space-around;">

                    <div class="card1-text">类型：{{ item.roledec }}</div>
                    <div class="card1-text">状态：{{ item.statedec }}
                        <div class="btn-new" @click="noAllow(item)" v-if="item.state == 1">禁用</div>
                        <div class="btn-news" @click="Allow(item)" v-else-if="item.state == 2">启用</div>
                    </div>
                </div>
                <div style="display: flex;justify-content: space-around;">

                    <div class="card1-text">店铺名称：{{ item.storename }}</div>
                    <div class="card1-text">
                        代金券金额：<span v-if="item.voucher" style="color: red">{{ item.voucher }}元</span>
                    </div>
                </div>
                <div class="card1-text">注册时间：{{ item.time }}</div>
                <div style="display: flex;justify-content: space-around;" v-if="item.dec">

                    <div class="card1-text" style="color:red">备注：{{ item.dec }}</div>
                </div>
                <div class="btn">
                    <div class="btn1" @click="btn3(item)">修改余额</div>
                    <div class="btn1" @click="btn4(item)">重置密码</div>
                    <div class="btn2" @click="btn1(item)">变更记录</div>
                    <div class="btn2" @click="btn2(item)">发放记录</div>
                </div>
            </div>
            <div class="sao" @click="getUrl">
                <van-loading style="color: #000;" v-if="loadings" size="24px"><span
                        style="color: #000;">拉起扫码中...</span></van-loading>
                <span v-else> 扫一扫</span>
            </div>
            <!-- <div class="addStore" @click="addMember">
          新增商户
        </div> -->
        </div>
    </div>
</template>
  
<script>
import { indexdata, resetPwd, allow, ban , scandata} from "@/api/fulfil.js";
export default {
    name:'President',
    data() {
        return {
            agent: {},
            store: {},
            ticket: {},
            list: [],
            loadings:false,
        };
    },
    created() { },
    mounted() {
       /*   let uid = localStorage.getItem("agentids");
         if (!uid) {
           this.$Toast("请先登录！");
           this.$router.push({
             path: "/login",
           });
         } else {
           this.getIndex();
         } */
    },
    activated() {
          let uid = localStorage.getItem("agentids");
          if (!uid) {
            this.$Toast("请先登录！");
            this.$router.push({
              path: "/login",
            });
          } else {
            this.getIndex();
          }
    },
    methods: {
        //新增商户
        addMember() {
            this.$router.push({
                path: "/addstore",
            });
        },
        //退出登录
        reset() {
            localStorage.removeItem("adminid");
            localStorage.removeItem("agentid");
            localStorage.removeItem("agentids");
            localStorage.removeItem("phone");
            localStorage.removeItem("password");
            localStorage.removeItem("role");
            this.$router.push({
                path: "/login",
            });
        },

        btn3(item) {
            localStorage.setItem("adminid", item.id);
            this.$router.push({
                path: "/supertubedit",
                query: { item: item },
            });
        },
        btn4(item) {
            this.resetPwd(item);
        },
        getUrl() {
      this.loadings = true;
      let that = this;
      let wechaturl = window.location.href;

      scandata({
        agentid: localStorage.getItem("agentid"),
        url: wechaturl,
      }).then((res) => {
        if(res.data.code == 0){
          that.ticket = res.data.data;
        console.log(wx);
        wx.config({
          // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出
          debug: false,
          appId: that.ticket.appId, // 必填，公众号的唯一标识
          timestamp: that.ticket.timestamp, // 必填，生成签名的时间戳
          nonceStr: that.ticket.noncestr, // 必填，生成签名的随机串
          signature: that.ticket.signature, // 必填，签名
          jsApiList: ["getLocation", "openLocation", "scanQRCode"], // 必填，需要使用的JS接口列表
          openTagList: ["getLocation", "openLocation", "scanQRCode"], // 可选，需要使用的开放标签列表，例如['wx-open-launch-app']
        });
        wx.ready(() => {
          wx.scanQRCode({
            needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
            scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是一维码，默认二者都有
            success: function (res) {
                console.log(res,'res1');
              window.location.href = res.resultStr;
            },
            fail: (err) => {
              this.$Toast(err);
              console.log(err,'err');
            },
          });
        });
        }else{
          this.$Toast(res.data.msg);
        }

        this.loadings = false;
        console.log("res11111", res);
      
      });
    },
        //禁用
        noAllow(item) {
            ban({
                adminid: localStorage.getItem("agentids"),
                agentid: item.id
            })
                .then((res) => {
                    if (res.data.code == 0) {
                        this.$Toast("该店长账户禁用成功！");
                        this.getIndex();
                    } else {
                        this.$Toast(res.data.msg);
                    }
                })
                .catch((error) => {
                    console.log(error);
                });
        },
        //启用
        Allow(item) {
            allow({
                adminid: localStorage.getItem("agentids"),
                agentid: item.id
            })
                .then((res) => {
                    if (res.data.code == 0) {
                        this.$Toast("该店长账户启用成功！");
                        this.getIndex();
                    } else {
                        this.$Toast(res.data.msg);
                    }
                })
                .catch((error) => {
                    console.log(error);
                });
        },
        //重置密码
        resetPwd(item) {
            resetPwd({
                adminid: localStorage.getItem("agentids"),
                agentid: item.id
            })
                .then((res) => {
                    if (res.data.code == 0) {
                        this.$Toast("该店长密码重置成功！");
                    } else {
                        this.$Toast(res.data.msg);
                    }
                })
                .catch((error) => {
                    console.log(error);
                });
        },
        /* 获取当前页面数据 */
        getIndex() {
            indexdata({
                agentid: localStorage.getItem("agentids"),
            })
                .then((res) => {
                    this.list = res.data.data.agents;
                    this.agent = res.data.data.agent;
                    console.log(res);
                })
                .catch((error) => {
                    console.log(error);
                });
        },
        btn1(item) {
            localStorage.setItem("adminid", item.id);
            this.$router.push({
                path: "/record1",
            });
        },
        btn2(item) {
            localStorage.setItem("adminid", item.id);
            this.$router.push({
                path: "/record2",
            });
        },
    },
};
</script>
  
<style scoped>
.content {
    position: relative;
    padding-bottom: 2rem;
    overflow: hidden;
    width: 100%;
    min-height: 100vh;
    background: #e1f7fc;
}

.card1 {
    overflow: hidden;
    margin: 0.3rem auto 0;
    padding: 0 0.5rem 0.25rem 0.5rem;
    width: 84%;
    background: #fff;
    border-radius: 0.375rem;
}

.card1-title {
    margin-top: 0.2rem;
    font-size: 0.4125rem;
    font-weight: 600;
    color: #000;
}

.card1-text {
    flex: 1;
    display: inline-block;
    margin: 0.25rem 0 0 0.2rem;
    font-size: 0.3125rem;
    font-weight: 600;
    color: #000;
}

.card1-text1 {
    margin: 0.25rem 0 0 0.2rem;
    font-size: 0.3125rem;
    font-weight: 600;
    color: #000;
    text-align: center;
}

.btn {
    margin-top: 0.6rem;
    display: flex;
    /* 应用Flex布局 */
    justify-content: space-between;
    /* 控制盒子之间的对齐方式 */
}

.btn1 {
    padding: 0 .3rem;
    height: 0.75rem;
    color: #000;
    text-align: center;
    line-height: 0.75rem;
    border-radius: 0.375rem;
    background-color: #3cc9e8;
}

.btn4 {
    margin: 20px 30px 20px 0;
    float: right;
    width: 2.4rem;
    height: 0.75rem;
    color: #000;
    text-align: center;
    line-height: 0.75rem;
    border-radius: 0.375rem;
    background-color: #3cc9e8;
}

.s-card-text {
    margin: 20px 30px 20px 20px;
    height: 0.75rem;
    line-height: 0.75rem;
    float: left;
    color: #000;
    font-size: 0.45rem;
    font-weight: 600;
}

.btn2 {
    padding: 0 .3rem;
    height: 0.75rem;
    line-height: 0.75rem;
    text-align: center;
    color: #000;
    border-radius: 0.375rem;
    background-color: #ffbe4c;
}

.btn-new {
    display: inline-block;
    padding: .1rem .2rem;
    color: #fff;
    border-radius: 0.375rem;
    background-color: #f44;
}

.btn-news {
    display: inline-block;
    padding: .1rem .2rem;
    color: #fff;
    border-radius: 0.375rem;
    background-color: #07c160;
}


.addStore {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 1rem;
    font-size: .4rem;
    text-align: center;
    color: #AD3516;
    background: linear-gradient(180deg, #FFE9C6, #FFD584);
    box-shadow: 0px 3px 8px 0px rgba(150, 51, 20, 0.42);
    line-height: 1rem;
    border-radius: .5rem;
}

.sao {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    text-align: center;
    height: 1rem;
    line-height: 1rem;
    font-size: 0.35rem;
    border-radius: 0.5rem;
    background-color: #ffbe4c;
    font-weight: 600;
}</style>